//
//  UIImage+RBAdd.m
//  GXSign
//
//  Created by 蓝其 on 16/11/14.
//  Copyright © 2016年 GX. All rights reserved.
//

#import "UIImage+RBAdd.h"

@implementation UIImage(RBAdd)

+ (UIImage *)rbMaskImageWithColor: (UIColor *)color width: (CGFloat)width height: (CGFloat)height radius: (CGFloat)radius
{
    UIGraphicsBeginImageContext(CGSizeMake(width, height));
    CGContextRef context = UIGraphicsGetCurrentContext();
    [color set];
    
    CGContextAddArc(context, radius, radius, radius, -M_PI, -M_PI/2, NO);
    CGContextAddLineToPoint(context, 0, 0);
    CGContextClosePath(context);
    CGContextFillPath(context);
    CGContextAddArc(context, width-radius, radius, radius, -M_PI/2, 0, NO);
    CGContextAddLineToPoint(context, width, 0);
    CGContextClosePath(context);
    CGContextFillPath(context);
    CGContextAddArc(context, width-radius, height-radius, radius, 0, M_PI/2, NO);
    CGContextAddLineToPoint(context, width, height);
    CGContextClosePath(context);
    CGContextFillPath(context);
    CGContextAddArc(context, radius, height-radius, radius, M_PI/2, M_PI, NO);
    CGContextAddLineToPoint(context, 0, height);
    CGContextClosePath(context);
    CGContextFillPath(context);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

- (UIImage *)renderImage
{
    return [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}

+ (UIImage *)renderImageWithName:(NSString *)name
{
    UIImage *image = [UIImage imageNamed:name];
    return [image renderImage];
}


@end
